#pragma once
#include "gtest/gtest.h"
#include "TestData/model/QuadShell_OneEle.hpp"
#include "SGFem/Pre/Assembly/Assembly.h"
#include "SGFem/ShellSecCalculator/ShellSectionParser1.h"
#include "SGFem/ElementCalculator/Factory/ElementCalculatorFactory.h"
#include "../../Plate/MITC3PlateCalculator.h"

using SG::Algebra::Matrix;
using SG::DataStructure::FEM::IsotropicMaterial;
using SG::DataStructure::FEM::ElementTypes;
using SG::FEMSolver::AssemblyEigen;
using namespace SG::FEMSolver::Element;
using SG::FEMSolver::Element::ShellSectionParser1; // 使用新的解析类

class MITC3PlateCalculatorTest : public ::testing::Test
{
public:
    virtual void SetUp() override
    {
        localCoord = Matrix (3, 2, {0, 0,
                                    1, 0,
                                    0, 1,});

        IsotropicMaterial mat;
        mat.m_id = 1;
        mat.m_E = 30.0;
        mat.m_nu = 0.3;
        mat.m_G = 1.153846153846154e+01;
        
        // 创建壳截面解析器
        ShellSectionParser1 parser;
        parser.SetMaterial(1, mat); // 设置材料
        
        // 创建PSHELL截面数据
        SG::DataStructure::FEM::PSHELLData section;
        section.m_id = 1;
        section.m_thickness = 0.5;
        section.m_mId1 = 1; // 膜材料ID
        section.m_mId2 = 1; // 弯曲材料ID
        section.m_mId3 = 1; // 剪切材料ID
        section.m_ts = 5.0/6.0; // 剪切修正系数
        
        // 计算截面属性
        parser.CalcCommonSectionProp(nullptr, section, materialConst);

        for (int iNode = 0; iNode < 3; ++iNode)
        {
            thickness[iNode] = 0.5;
        }
    }
protected:
    Matrix localCoord;
    Real thickness[3];
    ShellSectionProp1 materialConst; // 使用新的截面属性结构
};

TEST_F (MITC3PlateCalculatorTest, MITC3PlateTest)
{
    // Test data
    MITC3PlateCalculator plateCalc;
    plateCalc.Initialize ();
    auto kbTest = plateCalc.ComputeStiffness (localCoord, thickness, materialConst);

    // Target data
    Matrix kbTarget(9, 9, {  
   4.8076923e+00,   1.2019231e+00,  -1.2019231e+00,  -2.4038462e+00,   0.0000000e+00,  -1.2019231e+00,  -2.4038462e+00,   1.2019231e+00,   0.0000000e+00,
   1.2019231e+00,   6.3244048e-01,  -3.1192766e-01,  -4.0064103e-01,  -6.0096154e-02,  -1.4880952e-01,  -8.0128205e-01,   2.2893773e-01,   6.0096154e-02,
  -1.2019231e+00,  -3.1192766e-01,   6.3244048e-01,   8.0128205e-01,   6.0096154e-02,   2.2893773e-01,   4.0064103e-01,  -1.4880952e-01,  -6.0096154e-02,
  -2.4038462e+00,  -4.0064103e-01,   8.0128205e-01,   2.4038462e+00,   4.0064103e-01,   1.2019231e+00,   0.0000000e+00,   0.0000000e+00,   4.0064103e-01,
   0.0000000e+00,  -6.0096154e-02,   6.0096154e-02,   4.0064103e-01,   2.6041667e-01,   2.0032051e-01,  -4.0064103e-01,   2.0032051e-01,   1.4022436e-01,
  -1.2019231e+00,  -1.4880952e-01,   2.2893773e-01,   1.2019231e+00,   2.0032051e-01,   7.7266484e-01,   0.0000000e+00,  -5.1510989e-02,   2.0032051e-01,
  -2.4038462e+00,  -8.0128205e-01,   4.0064103e-01,   0.0000000e+00,  -4.0064103e-01,   0.0000000e+00,   2.4038462e+00,  -1.2019231e+00,  -4.0064103e-01,
   1.2019231e+00,   2.2893773e-01,  -1.4880952e-01,   0.0000000e+00,   2.0032051e-01,  -5.1510989e-02,  -1.2019231e+00,   7.7266484e-01,   2.0032051e-01,
   0.0000000e+00,   6.0096154e-02,  -6.0096154e-02,   4.0064103e-01,   1.4022436e-01,   2.0032051e-01,  -4.0064103e-01,   2.0032051e-01,   2.6041667e-01,
   });

    // Check
    ASSERT_TRUE(kbTest == kbTarget);
}